﻿@inject Microsoft.AspNetCore.Hosting.IWebHostEnvironment HostingEnvironment
@{
    ShowTenantDto tenant = ViewBag.CurrentTenant;
    string tenantIcoUrl = "/favicon.ico";
    string tenantThumbnailUrl = "/images/no-thumbnail.png";
    string tenantImageUrl = "/images/no-image.png";
    string tenantShortName = "null";
    string tenantDescription = "null";
    if (tenant != null)
    {
        if (tenant.Id == "0")
        {
            tenantThumbnailUrl= "/images/tenant/logo.png";
            tenantImageUrl = "/images/tenant/trademark.png";
            tenantIcoUrl = "/images/tenant/ico.ico";
        }
        else
        {
            if (!tenant.ThumbnailPostfix.IsNullOrEmpty())
            {
                var fileName = "image" + tenant.ThumbnailPostfix;
                tenantThumbnailUrl = Url.Content("~/File/GetImage/Attachment/TenantThumbnail/" + tenant.Id) + "?fileName=" + (fileName) + "&random=" + new Random().Next();
            }
            if (!tenant.ImagePostfix.IsNullOrEmpty())
            {
                var fileName = "image" + tenant.ImagePostfix;
                tenantImageUrl = Url.Content("~/File/GetImage/Attachment/TenantImage/" + tenant.Id) + "?fileName=" + (fileName) + "&random=" + new Random().Next();
            }
            if (tenant.HasIco == 1)
            {
                var fileName = "ico.ico";
                tenantIcoUrl = Url.Content("~/File/GetImage/Attachment/TenantIco/" + tenant.Id) + "?fileName=" + (fileName) + "&random=" + new Random().Next();
            }
        }

        tenantShortName = tenant.ShortName.IsNullOrEmpty() ? "Undefined" : tenant.ShortName;
        tenantDescription = tenant.Description.IsNullOrEmpty() ? "Undefined" : tenant.Description;
    }

    string theme = ViewBag.Theme;
    var themeCss = theme.IsNullOrEmpty() ? "site-theme.min.css" : "site-theme-" + theme + ".min.css";

    List<ConfigItem> layoutComponents = ViewBag.LayoutComponents;
    string floatNavArticleId = "";
    string floatAdvArticleId = "";
    string footerArticleId = "";
    if (layoutComponents != null)
    {
        var floatNav = layoutComponents.Find(x => x.Attribute1.ToLower() == "floatNav".ToLower());
        if (floatNav != null) floatNavArticleId = floatNav.Attribute2;
        var floatAdv = layoutComponents.Find(x => x.Attribute1.ToLower() == "floatAdv".ToLower());
        if (floatAdv != null) floatAdvArticleId = floatAdv.Attribute2;
        var footer = layoutComponents.Find(x => x.Attribute1.ToLower() == "Footer".ToLower());
        if (footer != null) footerArticleId = footer.Attribute2;
    }
    string topMenuItemId = ViewBag.TopMenuItemId;
    List<ListMenuItemsDto> menuItemList = ViewBag.MenuItems;

    var landingPageUrl = ViewBag.LandingPageUrl;

    ShowSelfModel user = ViewBag.CurrentUser;
    var userAvatarUrl = Url.Content("~/images/avatar.png");
    if (user != null)
    {
        if (!user.ThumbnailPostfix.IsNullOrEmpty())
        {
            var fileName = "thumbnail" + user.ThumbnailPostfix; ;
            userAvatarUrl = Url.Content("~/File/GetImage/Attachment/UserThumbnail/" + user.ActorId) + "?fileName=" + (fileName) + "&random=" + new Random().Next();
        }
    }

    ConfigItem portal = ViewBag.CurrentPortal;
    bool portalIsNull = portal == null;
    string portalId = portalIsNull ? "Undefined" : portal.Id.ToString();
    string portalAbbr = portalIsNull ? "Undefined" : portal.Attribute2;
    IgnoreBody();
}

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width,initial-scale=1">
    <meta name="keywords" content="@ViewBag.Keywords">
    <meta name="description" content="@tenantDescription">
    <title>@ViewData["Title"] - @tenantShortName</title>

    <link rel="bookmark" href='@Url.Content("~"+landingPageUrl)' content="@tenantDescription" />
    <link rel="shortcut icon" href="@tenantIcoUrl" type="image/x-icon" />

    <link rel="stylesheet" href='@Url.Content("~/lib/bootstrap/3.3.7/css/bootstrap.min.css")'>
    <link rel="stylesheet" href='@Url.Content("~/lib/fontawesome/4.7.0/css/fontawesome.min.css")'>

    @BundlerHelper.Render(HostingEnvironment.ContentRootPath, Url.Content("~/app/site/css/site.min.css"))
    @BundlerHelper.Render(HostingEnvironment.ContentRootPath, Url.Content("~/app/site/css/" + themeCss))


    <script type="text/javascript">
        var ctx = '@Url.Content("~/")';
    </script>
</head>

<body>
    @if (!floatNavArticleId.IsNullOrEmpty())
    {<div id="floatNav" class="layout-float-nav"></div>}
    @if (!floatAdvArticleId.IsNullOrEmpty())
    {
        <div id="floatAdv"></div>
    }
    <header style="height:71px">
        <div id="layout-header" class="layout-header header-background">
            <a href="#"><img class="tnt-logo" src="@tenantImageUrl"></a>
            <div class="layout-main-menu">
                <ul class="nav-list" style="margin: 0 30px 0 0">
                    @{
                        if (menuItemList != null)
                            foreach (var menuItem in menuItemList.Where(x => x.ParentId == topMenuItemId))//level1
                            {
                                @if (menuItem.Type != (int)MenuItemType.Directory)
                                {
                                    <li>
                                        @{
                                            if (menuItem.Type == (int)MenuItemType.OuterLink)
                                            {
                                                <a href='@(menuItem.Url)' target='_blank'>@menuItem.Name</a>
                                            }

                                            else if (menuItem.IsBlankTarget)
                                            {
                                                <a class='menu-item-a' href='@Url.Content("~/" + menuItem.Url)' target='_blank'>@menuItem.Name</a>
                                            }
                                            else
                                            {
                                                <a class='menu-item-b' href="#" data-url='@Url.Content("~/" + menuItem.Url)' data-tag='@menuItem.IsTransparentHeader'>@menuItem.Name</a>
                                            }
                                        }
                                    </li>

                                }
                                else
                                {

                                    var children = menuItemList.FindAll(x => x.ParentId == menuItem.Id);
                                    var isGrandFather = children.All(x => x.Type == (int)MenuItemType.Directory);
                                    var isdFather = children.All(x => x.Type != (int)MenuItemType.Directory);
                                    if (isdFather)
                                    {
                                        <li class="has-child">
                                            <a href="javascript:;" target="_self">
                                                @menuItem.Name<i class="glyphicon glyphicon-menu-right pull-right hidden-sm hidden-md hidden-lg"></i>
                                            </a>

                                            <div class="child-list-container">
                                                <ul class="child-list main-menu-background">
                                                    <h4 class="one-child">
                                                        @menuItem.Name
                                                        @foreach (var menuItemChild in menuItemList.Where(x => x.ParentId == menuItem.Id))
                                                        {
                                                            if (menuItemChild.Type != (int)MenuItemType.Directory)
                                                            {
                                                                <li>
                                                                    @if (menuItemChild.Type == (int)MenuItemType.OuterLink)
                                                                    {
                                                                        <a href='@(menuItemChild.Url)' target='_blank'>@menuItemChild.Name</a>
                                                                    }
                                                                    else if (menuItemChild.IsBlankTarget)
                                                                    {
                                                                        <a class='menu-item-a' href='@Url.Content("~/" + menuItemChild.Url)' target='_blank'>@menuItemChild.Name</a>
                                                                    }
                                                                    else
                                                                    {
                                                                        <a class='menu-item-b' href="#" data-url='@Url.Content("~/" + menuItemChild.Url)' data-tag='@menuItemChild.IsTransparentHeader'>@menuItemChild.Name</a>
                                                                    }
                                                                </li>
                                                            }
                                                        }

                                                    </h4>
                                                </ul>
                                            </div>
                                        </li>
                                    }
                                    else if (isGrandFather)
                                    {
                                        <li class="has-child">
                                            <a href="javascript:;" target="_self">@menuItem.Name<i class="glyphicon glyphicon-menu-right pull-right hidden-sm hidden-md hidden-lg"></i></a>
                                            <div class="child-list-container" style="width: 450px; display: none; opacity: 0;" show-list="0">
                                                <ul class="child-list main-menu-background">
                                                    @{
                                                        foreach (var menuItemChild in menuItemList.Where(x => x.ParentId == menuItem.Id))
                                                        {
                                                            <h4 class="child-title">
                                                                @menuItemChild.Name
                                                                <span class="newCon sub-title-new" style="display: inline-block">NEW</span>
                                                                @foreach (var menuItemGrandChild in menuItemList.Where(x => x.ParentId == menuItemChild.Id))
                                                                {
                                                                    <li>
                                                                        @if (menuItemGrandChild.Type == (int)MenuItemType.OuterLink)
                                                                        {
                                                                            <a href='@(menuItemGrandChild.Url)' target='_blank'>@menuItemGrandChild.Name</a>
                                                                        }
                                                                        else if (menuItemGrandChild.IsBlankTarget)
                                                                        {
                                                                            <a class='menu-item-a' href='@Url.Content("~/" + menuItemGrandChild.Url)' target='_blank'>@menuItemGrandChild.Name</a>
                                                                            @*<span class="newCon" style="display:none">NEW</span>*@
                                                                        }
                                                                        else
                                                                        {
                                                                            <a class='menu-item-b' href="#" data-url='@Url.Content("~/" + menuItemGrandChild.Url)' data-tag='@menuItemGrandChild.IsTransparentHeader'>@menuItemGrandChild.Name</a>
                                                                            @*<span class="newCon" style="display:none">NEW</span>*@
                                                                        }
                                                                    </li>
                                                                }

                                                            </h4>

                                                        }
                                                    }
                                                </ul>
                                            </div>
                                        </li>
                                    }

                                }
                            }
                    }

                </ul>
            </div>
            <div id="right-menu" class="layout-main-menu" style="width:200px;margin:0px;position:absolute;top:0px;right:5px">
                @if (!ViewBag.Anonymous)
                {
                    <ul id="user-menu" class="nav-list" style="margin: 0">
                        <li class="has-child" style="padding: 0 0 0 30px">
                            <a href="javascript:;" target="_self">
                                <img src="@userAvatarUrl" style="width: 32px; height: 32px; border-radius: 50%; margin-right: 6px;">@user.Name
                                <i class="glyphicon glyphicon-menu-right pull-right hidden-sm hidden-md hidden-lg"></i>
                            </a>

                            <div class="child-list-container">
                                <ul class="child-list main-menu-background">
                                    <h4 class="one-child">
                                        用户自助
                                        <li>
                                            <a onclick="manageSelf()">
                                                <i class="fa fa-male"></i> 个人中心
                                            </a>
                                        </li>
                                        <li>
                                            <a onclick="showUploadThumbnailModal()">
                                                <i class="fa fa-user"></i> 上传图像
                                            </a>
                                        </li>
                                        <li>
                                            <a onclick="showChangePasswordModal()">
                                                <i class="fa fa-key"></i> 修改密码
                                            </a>
                                        </li>
                                        <li>
                                            <a href="#" onclick="loginOff()">
                                                <i class="fa fa-sign-out"></i> 退出登录
                                            </a>
                                        </li>


                                    </h4>
                                </ul>
                            </div>
                        </li>
                    </ul>
                }

            </div>
        </div>


    </header>

    <main role="main">
        @RenderBody()
    </main>

    @if (!footerArticleId.IsNullOrEmpty())
    {
        <footer id="footer" class="layout-footer text-muted">
        </footer>
    }
    @BundlerHelper.Render(HostingEnvironment.ContentRootPath, Url.Content("~/app/site/js/portal-init.min.js"))
</body>
</html>

<script>

    $(function () {
        var getTextUrl = "/Scc/Article/GetShowModelJson/none/Body/";
        if ('@floatNavArticleId') updateElementHtml(getTextUrl + '@floatNavArticleId', 'floatNav');
        if ('@floatAdvArticleId') updateElementHtml(getTextUrl + '@floatAdvArticleId', 'floatAdv');
        if ('@footerArticleId') updateElementHtml(getTextUrl + '@footerArticleId', 'footer');
    });

    function manageSelf() {
        var url = '@Url.Content("~/Sys/User/ManageSelf")'
         renderElement(url, 'body-main');
    }

    function showUploadThumbnailModal() {
        ys.openDialog({
            title: "上传头像",
            height:'580px',
            content: '@Url.Content("~/Sys/User/UploadSelfAttachmentModal")' + '?index=squarethumbnail',
            callback: function (index, layero) {
                location.reload();
            }
        });
    }

    function showChangePasswordModal() {
        ys.openDialog({
            title: "修改密码",
            height: "320px",
            content: '@Url.Content("~/Sys/User/ChangeSelfPasswordModal")',
            callback: function (index, layero) {
                var frame = window[layero.find('iframe')[0]['name']];
                frame.saveForm(index);
            }
        });
    }


    function loginOff() {
         ys.ajax({
                url: '@Url.Content("~/Sys/User/Logoff")',
                type: "post",
                success: function (rst) {
                    if (rst.Flag == 1) {
                       location.href = '@Url.Content("~/Sys/User/Logon?portal="+ portalAbbr)';
                    }
                    else {
                        ys.msgError(rst.Message);
                    }
                }
            });
    }

    function reloadLocation() {
        location.reload();
    }

</script>





